/*
 * Copyright 2016-2021 the original author.All rights reserved.
 * Kingstar(honeysoft@126.com)
 * The license,see the LICENSE file.
 */

package com.aiteasoft.school.scores.serviceimpl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.teasoft.bee.osql.Condition;
import org.teasoft.bee.osql.Op;
import org.teasoft.bee.osql.SuidRich;
import org.teasoft.honey.osql.core.ConditionImpl;

import com.aiteasoft.school.scores.entity.Scores;
import com.aiteasoft.school.scores.service.ScoresForDeanService;
import com.automvc.common.jq.PageWarp;
import com.automvc.common.jq.Result;

/**
 * @author AiTeaSoft.com
 * @since  1.9
 * Create on 2021-01-18 18:29:23
 */
@Service
public class ScoresForDeanServiceImpl  implements ScoresForDeanService{  

	@Autowired
	SuidRich suidRich;

	@Override
	public Scores process(Scores entity) { 
		//Add the business logic if need. 放一些公共设置

		return entity;
	}
	
	@Override
	public boolean isWrongBizForUpdate(Result result, Scores entity) {
		//Add the business logic if need.
		if("FIN".equals(entity.getStatus())) {
			result.setErrorMsg("The recored don't allow to update!");
			return true;
		}
		return false;
	}

	@Override
	public PageWarp countAndSelect(Scores entity, int start, int size) {
	    Condition condition = getCondition(entity);
	    
		int total = suidRich.count(entity, condition);
		
		condition.start(start);
		condition.size(size);
		List<Scores> listPage=suidRich.select(entity, condition);
		
		return new PageWarp(total,listPage);
	}
	
	private Condition getCondition(Scores entity) {
		Condition condition=new ConditionImpl();
		//Add the business logic if need.
		
		return condition;
	}
	
	@Override
	public int update(Scores entity) {
		
		Scores scores=new Scores();
		scores.setId(entity.getId());
		scores.setScore(entity.getScore());
		scores.setRemark(entity.getRemark());
		
		scores.setUpdater("教务处老师");//TODO
		
		Condition condition=new ConditionImpl();
		condition.op("status", Op.nq, "FIN"); //状态为还没关闭的,才能修改
		
		return suidRich.update(scores,"score,remark,updater",condition);  
	}
	
	/*	public void initExam() {
			
			CurrentCoureseTeacherView view=new CurrentCoureseTeacherView();
			List<CurrentCoureseTeacherView> listView=suidRich.select(view);
			
			List<Assignclass> listStu;
			Assignclass assignclass=new Assignclass();
			List<Scores> listScores;
			CurrentCoureseTeacherView tempView;
			Scores scores;
			for (int i = 0;  listView!=null && i < listView.size(); i++) {
				tempView=listView.get(i);
				assignclass.setClassno(tempView.getClassno());
				listStu=suidRich.select(assignclass);
				listScores=new ArrayList<>();
				scores=new Scores();
				for (int j = 0;listStu!=null && j < listStu.size(); j++) {
					scores=new Scores();
					setFieldFromView(scores,tempView);
					setStudentInfo(scores, assignclass);
					listScores.add(scores);
				}
				suidRich.insert(listScores);
			}
		}
	
	private void setFieldFromView(Scores scores,CurrentCoureseTeacherView view){
		scores.setClassno(view.getClassno());
		scores.setTerm(view.getTerm());
		scores.setExamno(view.getExamno());
		scores.setSubject(view.getSubject());
		scores.setSubjectno(view.getSubjectno());
		scores.setTeachername(view.getName());
		scores.setTeacherno(view.getTeacherno());
		scores.setSchoolno(view.getSchoolno());
	}
	
	private void setStudentInfo(Scores scores,Assignclass assignclass){
		scores.setStuno(assignclass.getStuno());
		scores.setName(assignclass.getName());
		scores.setScore(0D); //0
	}
*/
}